39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_analog_in.h"
74#define DCMOTOR30_REG_FAULT_STATUS 0x00
75#define DCMOTOR30_REG_RC_STATUS1 0x01
76#define DCMOTOR30_REG_RC_STATUS2 0x02
77#define DCMOTOR30_REG_RC_STATUS3 0x03
78#define DCMOTOR30_REG_STATUS1 0x04
79#define DCMOTOR30_REG_STATUS2 0x05
80#define DCMOTOR30_REG_STATUS3 0x06
81#define DCMOTOR30_REG_STATUS4 0x07
82#define DCMOTOR30_REG_STATUS5 0x08
83#define DCMOTOR30_REG_CONFIG0 0x09
84#define DCMOTOR30_REG_CONFIG1 0x0A
85#define DCMOTOR30_REG_CONFIG2 0x0B
86#define DCMOTOR30_REG_CONFIG3 0x0C
87#define DCMOTOR30_REG_CONFIG4 0x0D
88#define DCMOTOR30_REG_CTRL0 0x0E
89#define DCMOTOR30_REG_CTRL1 0x0F
90#define DCMOTOR30_REG_CTRL2 0x10
91#define DCMOTOR30_REG_RC_CTRL0 0x11
92#define DCMOTOR30_REG_RC_CTRL1 0x12
93#define DCMOTOR30_REG_RC_CTRL2 0x13
94#define DCMOTOR30_REG_RC_CTRL3 0x14
95#define DCMOTOR30_REG_RC_CTRL4 0x15
96#define DCMOTOR30_REG_RC_CTRL5 0x16
97#define DCMOTOR30_REG_RC_CTRL6 0x17
98#define DCMOTOR30_REG_RC_CTRL7 0x18
99#define DCMOTOR30_REG_RC_CTRL8 0x19
117#define DCMOTOR30_FAULT_STATUS_FAULT 0x80
118#define DCMOTOR30_FAULT_STATUS_STALL 0x20
119#define DCMOTOR30_FAULT_STATUS_OCP 0x10
120#define DCMOTOR30_FAULT_STATUS_OVP 0x08
121#define DCMOTOR30_FAULT_STATUS_TSD 0x04
122#define DCMOTOR30_FAULT_STATUS_NPOR 0x02
128#define DCMOTOR30_CONFIG0_EN_OUT 0x80
129#define DCMOTOR30_CONFIG0_EN_OVP 0x40
130#define DCMOTOR30_CONFIG0_EN_STALL 0x20
131#define DCMOTOR30_CONFIG0_VSNS_SEL_AN 0x00
132#define DCMOTOR30_CONFIG0_VSNS_SEL_DIG 0x10
133#define DCMOTOR30_CONFIG0_VSNS_SEL_MASK 0x10
134#define DCMOTOR30_CONFIG0_CLR_FLT 0x02
135#define DCMOTOR30_CONFIG0_DUTY_CTRL_EN 0x01
141#define DCMOTOR30_RIPROPI_V_TO_MA 1.5
142#define DCMOTOR30_SCALING_FACTOR 1.5
148#define DCMOTOR30_NUM_CONVERSIONS 200
154#define DCMOTOR30_VREF_3V3 3.3
155#define DCMOTOR30_VREF_5V 5.0
156#define DCMOTOR30_VREF_DEFAULT DCMOTOR30_VREF_3V3
162#define DCMOTOR30_TIMEOUT_MS 2000
168#define DCMOTOR30_MOTOR_COAST 0
169#define DCMOTOR30_MOTOR_FORWARD 1
170#define DCMOTOR30_MOTOR_REVERSE 2
171#define DCMOTOR30_MOTOR_BRAKE 3
178#define DCMOTOR30_DEVICE_ADDRESS_A1A0_00 0x30
179#define DCMOTOR30_DEVICE_ADDRESS_A1A0_0Z 0x31
180#define DCMOTOR30_DEVICE_ADDRESS_A1A0_01 0x32
181#define DCMOTOR30_DEVICE_ADDRESS_A1A0_Z0 0x33
182#define DCMOTOR30_DEVICE_ADDRESS_A1A0_ZZ 0x34
183#define DCMOTOR30_DEVICE_ADDRESS_A1A0_Z1 0x35
184#define DCMOTOR30_DEVICE_ADDRESS_A1A0_10 0x36
185#define DCMOTOR30_DEVICE_ADDRESS_A1A0_1Z 0x37
186#define DCMOTOR30_DEVICE_ADDRESS_A1A0_11 0x38
204#define DCMOTOR30_MAP_MIKROBUS( cfg, mikrobus ) \
205 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
206 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
207 cfg.ipropi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
208 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
209 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
210 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
dcmotor30_return_value_t
DC Motor 30 Click return value data.
Definition dcmotor30.h:266
@ DCMOTOR30_OK
Definition dcmotor30.h:267
@ DCMOTOR30_ERROR
Definition dcmotor30.h:268
err_t dcmotor30_clear_fault(dcmotor30_t *ctx)
DC Motor 30 clear fault function.
void dcmotor30_cfg_setup(dcmotor30_cfg_t *cfg)
DC Motor 30 configuration object setup function.
err_t dcmotor30_write_reg(dcmotor30_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 30 write reg function.
void dcmotor30_clear_in2_pin(dcmotor30_t *ctx)
DC Motor 30 clear IN2 pin function.
uint8_t dcmotor30_get_fault_pin(dcmotor30_t *ctx)
DC Motor 30 get FAULT pin function.
err_t dcmotor30_read_reg(dcmotor30_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 30 read reg function.
err_t dcmotor30_calib_offset(dcmotor30_t *ctx)
DC Motor 30 calib offset function.
err_t dcmotor30_read_adc_volt(dcmotor30_t *ctx, float *data_out)
DC Motor 30 read IPROPI pin voltage level function.
err_t dcmotor30_read_adc_raw(dcmotor30_t *ctx, uint16_t *data_out)
DC Motor 30 read raw IPROPI ADC value function.
err_t dcmotor30_set_adc_vref(dcmotor30_t *ctx, float vref)
DC Motor 30 set vref function.
err_t dcmotor30_read_adc_volt_avg(dcmotor30_t *ctx, uint16_t num_conv, float *volt_avg)
DC Motor 30 read IPROPI pin voltage level average function.
void dcmotor30_drive_motor(dcmotor30_t *ctx, uint8_t state)
DC Motor 30 drive motor function.
void dcmotor30_set_in1_pin(dcmotor30_t *ctx)
DC Motor 30 set IN1 pin function.
err_t dcmotor30_default_cfg(dcmotor30_t *ctx)
DC Motor 30 default configuration function.
void dcmotor30_clear_in1_pin(dcmotor30_t *ctx)
DC Motor 30 clear IN1 pin function.
err_t dcmotor30_init(dcmotor30_t *ctx, dcmotor30_cfg_t *cfg)
DC Motor 30 initialization function.
err_t dcmotor30_get_out_current(dcmotor30_t *ctx, float *current)
DC Motor 30 get out current function.
void dcmotor30_set_in2_pin(dcmotor30_t *ctx)
DC Motor 30 set IN2 pin function.
DC Motor 30 Click configuration object.
Definition dcmotor30.h:244
analog_in_resolution_t resolution
Definition dcmotor30.h:256
float vref
Definition dcmotor30.h:257
uint32_t i2c_speed
Definition dcmotor30.h:253
pin_name_t in2
Definition dcmotor30.h:249
pin_name_t ipropi
Definition dcmotor30.h:247
pin_name_t scl
Definition dcmotor30.h:245
pin_name_t in1
Definition dcmotor30.h:250
pin_name_t sda
Definition dcmotor30.h:246
pin_name_t fault
Definition dcmotor30.h:251
uint8_t i2c_address
Definition dcmotor30.h:254
DC Motor 30 Click context object.
Definition dcmotor30.h:220
digital_out_t in2
Definition dcmotor30.h:222
i2c_master_t i2c
Definition dcmotor30.h:229
digital_in_t fault
Definition dcmotor30.h:226
uint8_t slave_address
Definition dcmotor30.h:233
float zero_curr_offset
Definition dcmotor30.h:235
digital_out_t in1
Definition dcmotor30.h:223
analog_in_t adc
Definition dcmotor30.h:230